/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.manage.controller;


import info.peigen.hotpot.common.core.result.manage.WebResult;
import info.peigen.hotpot.component.data.repository.beetlsql.filter.ManageDataAspect;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobChangeAllResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobCreateResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobDeleteResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleJobEditResult;
import info.peigen.hotpot.component.schedule.manage.form.*;
import info.peigen.hotpot.component.schedule.manage.service.ScheduleJobManageService;
import jakarta.validation.Valid;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

/**
 * <b>(ScheduleJobManageController)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@Controller
@Mapping("schedule/job")
public class ScheduleJobManageController {
    @Inject
    private ScheduleJobManageService scheduleJobManageService;

    @Mapping("page")
    @ManageDataAspect
    WebResult page(@Body ScheduleJobManageSearchForm form) {
        return WebResult.setSuccessResult().setInfo(scheduleJobManageService.page(form));
    }

    @Mapping("add")
    @ManageDataAspect
    WebResult add(@Valid @Body ScheduleJobManageAddForm form) {
        ScheduleJobCreateResult result = scheduleJobManageService.add(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("edit")
    @ManageDataAspect
    WebResult edit(@Valid @Body ScheduleJobManageEditForm form) {
        ScheduleJobEditResult result = scheduleJobManageService.edit(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("delete")
    WebResult delete(@Valid @Body ScheduleJobManageDeleteForm form) {
        ScheduleJobDeleteResult result = scheduleJobManageService.delete(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("changeAll")
    WebResult changeAllJobsEnable(@Valid @Body ScheduleJobManageChangeAllForm form) {
        ScheduleJobChangeAllResult result = scheduleJobManageService.changeAll(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

}